package info.ipeanut.toffeepulltorefresh;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.view.View;

/**
 * Created by chenshaosina on 16/8/10.
 */
public class ToffeeLoadingView extends View {

    private Paint paint;
    private Path path;
    private RectF ovalTop;
    private RectF ovalBottom;
    private int width,height;

    public ToffeeLoadingView(Context context) {
        super(context);
        init();

    }

    public ToffeeLoadingView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();

    }

    public ToffeeLoadingView(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        init();
    }

    private void init(){
        setWillNotDraw(false);
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setColor(Color.RED);
        paint.setStyle(Paint.Style.FILL);

        initTop();
        initBottom();

    }

    private void initBottom() {
        ovalBottom = new RectF();
    }

    private void initTop() {
        ovalTop = new RectF();
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        super.onMeasure(widthMeasureSpec, heightMeasureSpec);
        width = MeasureSpec.getSize(widthMeasureSpec);
        height = MeasureSpec.getSize(heightMeasureSpec);
    }


    @Override
    protected void onLayout(boolean changed, int left, int top, int right, int bottom) {
        super.onLayout(changed, left, top, right, bottom);
        ovalBottom.left = ovalTop.left = getLeft() - getPaddingLeft();
        ovalBottom.top = ovalTop.top = getTop();
        ovalBottom.right = ovalTop.right = getLeft() + width;
        ovalBottom.bottom = ovalTop.bottom = getTop() + height/2;

//        ovalBottom.set(ovalTop);
    }

    @Override
    protected void onSizeChanged(int w, int h, int oldw, int oldh) {
        super.onSizeChanged(w, h, oldw, oldh);
    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        canvas.drawOval(ovalTop, paint);


        canvas.drawOval(ovalBottom,paint);

    }
}
